﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;

public partial class databack : System.Web.UI.Page
{
    SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["cn"]);
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Session["type"].ToString().Trim() != "0")
        //{
        //    Response.Write("<script>javascript:alert('对不起,您没有这个权限');history.back();</script>");
        //    Response.End();
        //}
        string path = "D:/";
        if (Directory.Exists(path) == false)//如果不存在就改变存储路径到C:/database/目录
        {
            path = "C:/database/";
            Directory.CreateDirectory(path);
            
        }
        path = path + "gouwujiajunet65023.dat";
        SqlCommand mycmd = new SqlCommand();
        string myExecuteQuery = "backup database gouwujiajunet65023 to disk='" + path + "'";
        SqlCommand myCommand = new SqlCommand(myExecuteQuery, myConnection);
        myCommand.Connection.Open();
        myCommand.ExecuteNonQuery();
        myConnection.Close();
        string scr = "<script>javascript:alert('数据成功备份于" 
                     + path 
                     + "');location.href='sy.aspx';</script>";
        Response.Write(scr);
        Response.End();
    }
}
